package fun.easycode.webterminal.adapter.api;

import fun.easycode.webterminal.common.contract.PageDTO;
import fun.easycode.webterminal.common.contract.R;
import fun.easycode.webterminal.service.TopologyService;
import fun.easycode.webterminal.service.cmd.TopologyPageQry;
import fun.easycode.webterminal.service.cmd.TopologySaveCmd;
import fun.easycode.webterminal.service.dto.TopologyDTO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Tag(name = "拓扑")
@RestController
@RequestMapping("/api/topology")
public class TopologyApi {

    private final TopologyService topologyService;

    @Autowired
    public TopologyApi(TopologyService topologyService) {
        this.topologyService = topologyService;
    }

    @GetMapping("/page")
    @Operation(summary = "分页查询拓扑")
    public R<PageDTO<TopologyDTO>> page(TopologyPageQry cmd) {
        return topologyService.page(cmd);
    }

    @PostMapping("/save")
    @Operation(summary = "保存拓扑(新建/编辑)")
    public R<String> save(@RequestBody TopologySaveCmd cmd) {
        return topologyService.save(cmd);
    }

    @PostMapping("/delete")
    @Operation(summary = "删除拓扑")
    public R<String> delete(@RequestParam String id) {
        return topologyService.delete(id);
    }

    @GetMapping("/get-by-id")
    @Operation(summary = "根据id查询拓扑")
    public R<TopologyDTO> getById(@RequestParam String id) {
        return topologyService.getById(id);
    }
}
